package phoneBook;

import arcademis.Marshalable;
import arcademis.Stream;

public class PhoneAddress implements Marshalable {
	
	private Usuario usuario;
	private String phoneNumber = null;
	private String address = null;

	public PhoneAddress(){
		this.usuario = new Usuario();
		this.phoneNumber = null;
		this.address = null;
	}

	public PhoneAddress(String name, String lastName, String phoneNumber, String address){
		this.usuario = new Usuario(name, lastName);
		this.phoneNumber = phoneNumber;
		this.address = address;
	}

	public String getPhoneNumber() {
		return phoneNumber;
	}

	public String getAddress() {
		return address;
	}

	public boolean equals(Object o) {
		if(!(o instanceof PhoneAddress))
			return false;
		else {
			boolean sameName = this.usuario.equals(((PhoneAddress)o).usuario);
			boolean sameNumber = this.phoneNumber == ((PhoneAddress)o).phoneNumber;
			return sameName && sameNumber;
		}
	}

	public String toString() {
		return this.usuario.getNome() + ": " + this.phoneNumber;
	}

	public void marshal(Stream b) {
		try {
			b.write(phoneNumber);
			b.write(usuario);
			b.write(address);
		}
		catch(Exception e) {
			e.printStackTrace();
		}
	}

	public void unmarshal(Stream b) {
		try {
			this.phoneNumber = (String)b.readObject();
			this.usuario = (Usuario)b.readObject();
			this.address = (String)b.readObject();
		}
		catch(Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * @return the usuario
	 */
	public Usuario getUsuario() {
		return usuario;
	}

	/**
	 * @param usuario the usuario to set
	 */
	public void setUsuario(Usuario usuario) {
		this.usuario = usuario;
	}
}